﻿namespace EyeOpen.ViewModel
{
    using System.ComponentModel;
    using Microsoft.Practices.Composite.Events;
    using Microsoft.Practices.ServiceLocation;

    /// <summary>
    /// Provides common functionality for ViewModel classes
    /// </summary>
    public abstract class ViewModelBase : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        /// <summary>
        /// Initializes a new instance of the <see cref="ViewModelBase"/> class.
        /// </summary>
        /// <param name="theAggregator">The aggregator.</param>
        public ViewModelBase()
        {
            TheAggregator = ServiceLocator.Current.GetInstance<IEventAggregator>();
        }

        protected void OnPropertyChanged(string propertyName)
        {
            var handler = PropertyChanged;

            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        /// <summary>
        /// Gets or sets the aggregator.
        /// </summary>
        /// <value>The aggregator.</value>
        public IEventAggregator TheAggregator
        {
            get;
            set;
        }
    }
}